<!-- 项目经理确认传阅人选择的项目人员审批组件 -->
<template>
  <tl-sub-page :render="render" :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="1200px" @open="open" @close="close">
    <el-row>
      <el-col :span="24">
        <el-button type="danger" style="float: right" size="small" icon="el-icon-close" circle @click="doCancelEdit"></el-button>
      </el-col>
    </el-row>
    <el-form class="tl-form" style="margin-top: 15px" ref="form" :model="memberModel" :rules="rules" label-width="120px" :disabled="disableEditSubmit">
      <el-row>
        <el-col :span="24">
          <el-form-item label="退回传阅人">
            <el-select v-model="returnedcirculatedcodeArr" multiple placeholder="请选择">
              <el-option
                v-for="item in memberModel.dataList"
                :key="item.circulatedcode"
                :label="item.circulatedname"
                :value="item.circulatedcode">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="项目名称">
            <el-input v-model="memberModel.projectname" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-divider></el-divider>
      <div v-for="(item, index) in memberModel.dataList" :key="item.circulatedcode">
        <el-row>
          <el-col :span="24">
            <el-form-item label="传阅人">
              <tl-ref-user v-model="item.circulatedcode" :initDisplayData.sync="item.circulatedname" dataType="code" disabled :singleSelect="false"></tl-ref-user>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="项目人员">
              <tl-ref-user v-model="item.projectmembercode" :initDisplayData.sync="item.projectmembername" dataType="code" disabled :singleSelect="false"></tl-ref-user>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="member-divider" v-if="index < memberModel.dataList.length - 1"></div>
      </div>
    </el-form>
    <tl-approval-history ref="history" sourceType="MpmProjectCirculated" :sourceId="applyid" />
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="$refs.history.visible = true"><svg-icon icon-class="list" />审批历史</el-button>
    </div>
  </tl-sub-page>
</template>

<script>
  /** mixins */
  import { mixin_approval_edit } from '@tapui/mixins/mixin_approval_edit'
  /** 子组件 */
  /** 工具类 */
  import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
  /** VUE配置 */
  export default {
    mixins: [mixin_approval_edit],
    components: { },
    data() {
      return {
        moduleTitle: '项目传阅反馈人员',
        urlPrefix: '/mpm/projectCirculatedMember/',
        url: {
          // 额外的url
          queryConfirmMemberList: '/mpm/projectCirculatedMember/queryConfirmMemberList/',
          saveReturnedcirculatedCode: '/mpm/projectCirculated/saveReturnedcirculatedCode/',
          loadConfirmInfo: '/mpm/projectCirculated/load'
        },
        memberModel: {},
        applyid: 0,
        returnedcirculatedcodeArr: []
      }
    },
    methods: {
      loaded() {
        // 申请单id
        this.applyid = this.$parent.$parent.$parent.nodeModel.sourceid
        getAction(this.url.queryConfirmMemberList, { id: this.applyid }).then((res) => {
          if (res.success) {
            this.$set(this.memberModel, 'dataList', res.result.dataList)
          } else {
            this.$tap.alert(res.message, "warning")
          }
        })
        getAction(this.url.loadConfirmInfo, { id: this.applyid }).then((res) => {
          if (res.success) {
            this.$set(this.memberModel, 'projectname', res.result.projectname)
          } else {
            this.$tap.alert(res.message, "warning")
          }
        })
      },
      close() {
        this.$parent.$parent.$parent.approvalopinion = ''
      },
      /** 保存退回传阅人 **/
      async saveReturnedcirculatedCode(resolve, reject) {
        // 如果审批退回却没选择退回传阅人，则提示
        if (this.returnedcirculatedcodeArr.length <= 0) {
          this.$tap.alert('请选择退回传阅人', "warning")
          reject()
        } else {
          // 保存数据
          let res = await putAction(this.url.saveReturnedcirculatedCode, {
            code: this.returnedcirculatedcodeArr.join(','),
            id: this.applyid
          })
          if (res.success) {
            resolve()
          } else {
            this.$parent.$parent.$parent.loading = false
            this.$tap.alert(res.message, "warning")
            reject()
          }
        }
      },
      doCancelEdit() {
        this.$emit('close')
      }
    }
  }
</script>
<style>
  .member-divider {
    display: block;
    height: 1px;
    width: 100%;
    margin: 10px 0 14px 0;
    background-color: #DCDFE6;
    position: relative;
  }
</style>
